package algorithm;

import java.util.Arrays;

public class Hello {
    public Hello() {
        System.out.println("Algorithm Souls");
    }
    public static void main(String[]args){
        Integer a = 1;
        Integer b = 2;
        swap(a,b);
        System.out.println("a:"+a+",b:"+b);
        System.out.println("-------------------------");
        int[] tabs = new int[3];
        tabs[1] = 1;
        tabs[2] = 2;
        swap( tabs, tabs[1],tabs[2]);
        System.out.println(Arrays.toString(tabs));
    }

    /**
     * 交换，在方法体中，形参发生变化，不会影响实际参数,传递是引用
     * @param x
     * @param y
     */
    public static void swap(Integer x, Integer y) {
        Integer tmp = x;
        x = y;
        y = tmp;
        System.out.println(x+"|"+y);
    }

    /**
     * 交换，数组椒引用类型
     * @param tab
     * @param x
     * @param y
     */
    public static void swap( int[] tab, int x, int y) {
        int tmp = tab[x];
        tab[x] = y;
        tab[y] = tmp;
        System.out.println(Arrays.toString(tab));
    }
}